package com.medium.house.service.impl;

import java.util.List;
import com.medium.house.repository.HousePictureMapper;
import com.medium.house.response.HousePicsDto;
import com.medium.house.service.HousePictureService;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import javax.annotation.Resource;
import java.util.HashMap;
import com.medium.house.entity.HousePicture;
import org.springframework.stereotype.Service;

@Service
public class HousePictureServiceImpl implements HousePictureService
{

    @Autowired
    private HousePictureMapper housePictureMapper;

    @Override
    public int add(HousePicture dto)
    {
        return housePictureMapper.insert(dto);
    }

    @Override
    public int delete(long id)
    {
        return housePictureMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int update(HousePicture dto)
    {
        return housePictureMapper.updateByPrimaryKeySelective(dto);
    }

    @Override
    public HousePicture get(long id)
    {
        return housePictureMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<HousePicture> getByPage(
        int start,
        int limit,
        int orderby,
        int order)
    {
        if (start < 0) {start = 0;}
        if (limit <=0) {limit = 20;}
        if (orderby > HousePictureMapper.ORDERBY.length - 1 || orderby < 0) {orderby = 0;}
        if (order != 0) {order = 1;}

        Map<String, Object> args = new HashMap<>();
        // Add more parameters here
        return housePictureMapper.selectByPage(start, limit, HousePictureMapper.ORDERBY[orderby], HousePictureMapper.ORDER[order], args);
    }

    @Override
    public List<Long> getIdsByPage(
        int start,
        int limit,
        int orderby,
        int order)
    {
        if (start < 0) {start = 0;}
        if (limit <=0) {limit = 20;}
        if (orderby > HousePictureMapper.ORDERBY.length - 1 || orderby < 0) {orderby = 0;}
        if (order != 0) {order = 1;}

        Map<String, Object> args = new HashMap<>();
        // Add more parameters here
        return housePictureMapper.selectIdsByPage(start, limit, HousePictureMapper.ORDERBY[orderby], HousePictureMapper.ORDER[order], args);
    }

    @Override
    public long count()
    {
        Map<String, Object> args = new HashMap<>();
        // Add more parameters here
        return housePictureMapper.count(args);
    }

    @Override
    public List<HousePicsDto> getHousePictureByHouserID(Long houseID){
        return housePictureMapper.selectHousePictureByHouserID(houseID);
    }

}